var express = require('express');
var app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server);

server.listen(80);

app.use(express.static(__dirname));

io.sockets.on('connection', function (socket) {

    socket.isServer = false;

    socket.on("create_server", function(name){
        console.log("server create requested");
        socket.join(name);
        socket.isServer = true;
        socket.emit("server_created");
    });

    socket.on("request_server_list", function(){
        console.log("server list requested");
        var rooms = io.sockets.manager.rooms;
        var roomNames = [];
        for(name in rooms){
            roomNames.push(name);
        }
        socket.emit("server_list", roomNames);
    });

});